<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>车辆管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../static/css/style.css"  media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js" ></script>
    <script src="../../layui/layui.all.js" charset="utf-8"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js"></script>
</head>
<body>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="../../static/js/html5.js"></script>
<script src="../../static/js/respond.js"></script>
<![endif]-->

    <!--主体内容-->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-fluid layui-form-pane content-wrap">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">车牌号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="carNumbers" id="carNumbers"  autocomplete="off"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">登记时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" autocomplete="off" name="registerTime" id="registerTime" placeholder="开始 到 结束">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <button class="layui-btn add_btn" data-type="reload" onclick="searchBtn()" style="margin-left: 10px;"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn newsAdd_btn add_btn"  style="margin-left: 10px;"><i class="layui-icon layui-icon-add-1"></i>新增</button>
                    </div>
                </div>
                <table class="layui-hide" id="car"  lay-filter="eventBtn"></table>
                <script type="text/html" id="carTypeTpl">
                    {{#  if(d.carType === 1){ }}
                        小型轿车
                    {{#  } else if(d.carType === 2) { }}
                        客车
                    {{#  } else if(d.carType === 3) { }}
                        挂车
                    {{#  } else { }}
                    {{#  } }}
                </script>
                <script type="text/html" id="carProfileTpl">
                {{#  if(d.carType === 1){ }}
                自动
                {{#  } else if(d.carType === 2) { }}
                手动
                {{#  } else { }}
                {{#  } }}
                </script>
                <script type="text/html" id="imgTpl">
                    {{#   <span style="color: #007cff;" onclick=show('+d.id+')>查看图片</span> }}
                </script>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs change_btn btn-left" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn  layui-btn-xs delete_btn btn-left" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>
    <!--主体内容-->



    <script>

        function show(id) {
           ax.post({
                url: schoolWebUrl+"/api/carPicture/getInfo",
                type: "POST",
                data:{"carId":id,"type":2},
                contentType: "application/x-www-form-urlencoded",
                success: function(data){
                    var json=data.data;
                    layer.photos({
                        photos: json,
                        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                    });
                }
            });
        }
        //所属教练
        function coach(id){
          top.layui.layer.open({
                id:'',
                title : "教练",
                type : 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['90%', '80%'],
                content : "./school/cgs/coachList.html?carId="+id,
                success : function(layero, index){
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
          })
        }

        var tableIns;
        layui.use(['table', 'layer','element','laydate'], function(){
             var table = layui.table,
                 element = layui.element,
                 laydate =layui.laydate;

            laydate.render({
                elem: '#registerTime'
                ,type: 'date'
                ,format: 'yyyy-MM-dd'
                ,range: '到'
            });

             tableIns =ax.VTable({
                elem: "#car",
                id:"contenttable",
                url:schoolWebUrl+'/api/car/list',
                method: 'POST',
                cols: [[
                    {field:'序列号', width:80, title: '序列号', sort: true,type:'numbers'},
                    {field:'carNumbers', title: '车辆牌号',width: 150},
                    {field:'carModel', title: '车辆型号',width: 170},
                    {field:'carType', title: '车辆类型',width: 100, templet: '#carTypeTpl'},
                    {field:'carProfile', title: '车辆挡型', width: 100,templet: '#carProfileTpl'},
                    {field:'operatorName', title: '所属教练',width: 90,templet:function(d){
                            return '<span style="color: #007cff;" onclick=coach('+d.id+')>查看教练</span>';
                     }},
                    {field:'operatorName', title: '车辆图片',width: 90,templet:function(d){
                       return '<span style="color: #007cff;" onclick=show('+d.id+')>查看图片</span>';
                     }},
                    {field:'buyTime', title: '车辆购买时间',width: 160},
                    {field:'registerTime', title: '车辆注册登记日期',width: 160},
                    {field:'created', title: '创建时间',width: 160},
                    {field:'updated', title: '最后修改时间',width: 160},
                    {field:'right', title: '操作',width: 170,toolbar:"#barDemo"}
                ]]
            });

            table.on('tool(eventBtn)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    top.layer.confirm('确认删除？', function(index){
                        ax.post({
                            url: schoolWebUrl+"/api/car/delete",
                            type: "POST",
                            data:{"id":data.id},
                            contentType: "application/x-www-form-urlencoded",
                            success: function(data){
                               if(data.code==0){
                                    obj.del();
                                    layer.close(index);
                                    layer.msg(data.message, {icon: 6});
                                }else{
                                    layer.msg(data.message, {icon: 5});
                                }
                            }
                        });
                    });
                } else if(obj.event === 'edit'){
                    index = top.layui.layer.open({
                        title : "编辑",
                        type : 2,
                        fixed: true, //不固定
                        maxmin: true,
                        area: ['90%', '80%'],
                        content : "./school/cgs/carEdit.html?id="+data.id,
                        success : function(layero, index){
                            setTimeout(function(){
                                layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                                    tips: 3
                                });
                            },500)
                        }
                    })
                }
            });


        });
        function searchBtn(){
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    carNumbers:$("#carNumbers").val(),
                    registerTime:$("#registerTime").val()
                }
            });
        };
        function returnBtn(){
            layer.close(index);
            tableIns.reload({
                where: {}
              /*  ,page: { curr: 1 }*/
            });
        }
        //改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）



            $(".newsAdd_btn").click(function(){
                index = top.layui.layer.open({
                    id:'',
                    title : "新增车辆",
                    type : 2,
                    fixed: true, //不固定
                    maxmin: true,
                    area: ['90%', '80%'],
                    content : "./school/cgs/carAdd.html",
                    success : function(layero, index){
                         setTimeout(function(){
                            layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        },500)
                    }
                })
            });

    </script>
</body>
</html>